package com.ant.storage.controller;


import com.alibaba.excel.EasyExcel;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.InventoryExcelDto;
import com.ant.storage.dto.ProDto;
import com.ant.storage.pojo.PlannedProcurement;
import com.ant.storage.service.IPlannedProcurementService;
import com.ant.storage.service.impl.ProcurementServiceExper;
import com.ant.storage.vo.ProVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletContext;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hzd
 * @since 2023-07-26
 */
@RestController
@RequestMapping("/planned-procurement")
public class PlannedProcurementController {

    @Autowired
    private IPlannedProcurementService plannedProcurementService;

    @Autowired
    public ServletContext servletContext;

    @ApiOperation(value = "获取计划采购列表")
    @GetMapping("/getList")
    public ResultVo getPlannedPageList(ProDto dto) {
        Map<String, Object> map = plannedProcurementService.getPlannedPageList(dto);
        return ResultVo.success("操作成功", map);
    }


    @ApiOperation(value = "获取计划采购列表")
    @GetMapping("/getPlannedList")
    public ResultVo getPlannedList(ProDto dto) {
        List<PlannedProcurement> list = plannedProcurementService.getPlannedList(dto);
        return ResultVo.success("操作成功", list);
    }

    @ApiOperation(value = "上传计划采购")
    @PostMapping("/uploadCommodity")
    public ResultVo uploadCommodity(@RequestParam("file") MultipartFile file) {
        return plannedProcurementService.upload(file);
    }

    @ApiOperation(value = "上传计划采购")
    @PostMapping("/uploadCommoditys")
    public ResultVo uploadCommoditys(@RequestParam("file") MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), InventoryExcelDto.class, new ProcurementServiceExper(plannedProcurementService)).sheet().headRowNumber(1).doRead();
        return ResultVo.success("上传成功");
        //return plannedProcurementService.upload(file);
    }

    @ApiOperation(value = "获取分组计划采购单")
    @GetMapping("/getByPlannedNumber")
    public ResultVo getByPlannedNumber() {
        return plannedProcurementService.getByPlannedNumber();
    }

    @ApiOperation(value = "计划采购入库")
    @PostMapping("/saveWarehousing")
    public ResultVo saveWarehousing(@RequestBody List<ProVo> vo) {
        return plannedProcurementService.saveWarehousing(vo);
    }

}
